#include "Window_JonathanMain.h"
#include "Common.h"
#include "DataBaseManager.h"
#include "ReaderManager.h"
#include "Widget_Reader.h"

#include <QtGui/QDockWidget>
#include <QtGui/QToolBar>
#include <QtGui/QSplitter>

namespace Jonathan
{
   /**
    * @brief Initializes a new Jonathan main window.
    *
    * @param parent Parent widget.
    */
   Window_JonathanMain::Window_JonathanMain (QWidget *parent)
      : QMainWindow (parent), m_Options (0)
   {
      resize (1440, 1024);
      setWindowTitle ("Jonathan");
      setWindowIcon (Common::GetIcon (ICON_Jonathan));

      AddContent ();
   }

   /**
    * @brief Adds the docking content for Jonathan.
    *
    */
   void Window_JonathanMain::AddContent ()
   {
      QSplitter* splitter = new QSplitter (Qt::Horizontal, this);
      this->m_BookList = new Widget_BookList (splitter);
      splitter->addWidget (this->m_BookList);
      ReaderManager::GetInstance ()->setParent (splitter);
      splitter->addWidget (ReaderManager::GetInstance ());
      splitter->setCollapsible (0, true);
      splitter->setCollapsible (1, false);
      //splitter->setStretchFactor (0, 2);
      //splitter->setStretchFactor (1, 3);

      this->setCentralWidget (splitter);

      QToolBar* toolBar = this->addToolBar ("ToolBar_Main");
      toolBar->setIconSize (QSize (16, 16));

      toolBar->addAction (Common::GetIcon (Jonathan::ICON_Options), "Options", this, SLOT(ShowOptions()));
      toolBar->addSeparator ();
      toolBar->addAction (Common::GetIcon (Jonathan::ICON_Exit), "Exit", this, SLOT(close()));
   }

   /**
    * @brief Shows the options dialog.
    *
    */
   void Window_JonathanMain::ShowOptions ()
   {
      if (!this->m_Options)
         this->m_Options = new Window_Options (this);

      this->m_Options->exec ();
   }

   /**
    * @brief Destructor for Jonthan.
    *
    */
   Window_JonathanMain::~Window_JonathanMain()
   {
   }
}
